-
-
Notifications
You must be signed in to change notification settings - Fork 455
Add Ktor client integration #4527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
sentry-ktor/src/main/java/io/sentry/ktor/SentryKtorClientPlugin.kt
Outdated
Show resolved
Hide resolved
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
569c88a | 406.86 ms | 419.57 ms | 12.72 ms |
bc4c3ab | 420.27 ms | 462.92 ms | 42.65 ms |
94e993e | 404.49 ms | 439.62 ms | 35.13 ms |
df1fbd1 | 407.84 ms | 424.93 ms | 17.09 ms |
b5f9205 | 492.51 ms | 542.98 ms | 50.47 ms |
ec32652 | 354.67 ms | 385.71 ms | 31.04 ms |
1df63ce | 429.52 ms | 485.02 ms | 55.50 ms |
1fa99ff | 371.94 ms | 406.67 ms | 34.74 ms |
c3b3ac8 | 433.74 ms | 490.08 ms | 56.34 ms |
f316c06 | 427.39 ms | 464.94 ms | 37.55 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
569c88a | 1.58 MiB | 2.09 MiB | 519.08 KiB |
bc4c3ab | 1.58 MiB | 2.09 MiB | 518.90 KiB |
94e993e | 1.58 MiB | 2.09 MiB | 519.31 KiB |
df1fbd1 | 1.58 MiB | 2.09 MiB | 519.08 KiB |
b5f9205 | 1.58 MiB | 2.09 MiB | 519.31 KiB |
ec32652 | 1.58 MiB | 2.09 MiB | 518.89 KiB |
1df63ce | 1.58 MiB | 2.09 MiB | 518.90 KiB |
1fa99ff | 1.58 MiB | 2.09 MiB | 519.27 KiB |
c3b3ac8 | 1.58 MiB | 2.09 MiB | 518.90 KiB |
f316c06 | 1.58 MiB | 2.09 MiB | 519.08 KiB |
Good call. Working on this and trying to keep the extra dependencies at a minimum. I think we'll need to bring in the library containing the OkHttp client engine at least, which probably also depends on OkHttp itself. |
@sentry review |
PR DescriptionThis pull request introduces a new integration for the Sentry error monitoring platform with the Ktor HTTP client. The goal is to automatically capture unhandled exceptions, create breadcrumbs for HTTP requests, and support distributed tracing for applications using Ktor's client. Click to see moreKey Technical ChangesThe key technical changes include: 1. Creation of a Architecture DecisionsThe architectural decisions include: 1. Using Ktor's Dependencies and InteractionsThis integration depends on the Ktor HTTP client library, the Sentry Java SDK, and the kotlinx.coroutines library. It interacts with the Sentry SDK to capture exceptions, create breadcrumbs, and manage spans. It also interacts with the Ktor client pipeline to intercept requests and responses. Risk ConsiderationsPotential risks include: 1. Performance overhead due to span creation and breadcrumb generation. 2. Memory issues if response bodies are too large when capturing errors. 3. Thread safety issues if scopes are accessed concurrently. 4. Compatibility issues with future versions of Ktor or the Sentry SDK. 5. Incorrect configuration leading to excessive error reporting or missed errors. Notable Implementation DetailsNotable implementation details include: 1. The use of |
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt
Outdated
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Show resolved
Hide resolved
sentry-samples/sentry-samples-ktor-client/src/main/java/io/sentry/samples/ktorClient/Main.kt
Outdated
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Show resolved
Hide resolved
28e039a
to
bb52a1b
Compare
10fa401
to
8a42315
Compare
@romtsn Please let me know what you think about this approach: The approach is still not perfect because if the config block has some side effects, we would trigger them when creating the fake client. As a next step I want to set up an app using ProGuard and SAGP to ensure this works as intended. |
I've set up an Android sample with SAGP and it seems this approach to detect our OkHttp instrumentation doesn't work. As far as I understand, that's because the bytecode manipulation only adds the interceptor when we're in |
The OkHttp instrumentation is automatically added by SAGP, but users would have to manually set up this Ktor integration. |
oh dang, sorry I made you go through this. Yeah, this sounds like a job for the gradle plugin to do. Could you file an issue there please? And highlighting this in the docs for now sounds good too 👍 |
Okay, opened the issue in SAGP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM one question about reported integration name.
// Init | ||
SentryIntegrationPackageStorage.getInstance() | ||
.addPackage("maven:io.sentry:sentry-ktor-client", BuildConfig.VERSION_NAME) | ||
addIntegrationToSdkVersion("Ktor") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also have client in the name?
📜 Description
Add a Ktor client integration.
Functionality, options and tests are similar to our OkHttp integration.
💡 Motivation and Context
Part of #2684
💚 How did you test it?
End to end and manual tests
📝 Checklist
sendDefaultPII
is enabled.🔮 Next steps